#!/bin/bash

#set -x
#set -v
#/usr/share/texmf-texlive
cmd0="mkdir -p /usr/local/texlive/2013/texmf/tex/latex/mipsasm"
cmd1="cp ./mips.sty /usr/local/texlive/2013/texmf/tex/latex/mipsasm"
cmd2="mktexlsr"

#commands=( "$cmd1" "$cmd2" "$cmd3" )

commands[0]="$cmd0"
commands[1]="$cmd1"
commands[2]="$cmd2"



 
askcmdstr="su-to-root"
asksucmd="$askcmdstr -c"
canask=false
isroot=false

#===========================================

if [ "$(id -u)" != "0" ]; then
	isroot=false
else
	isroot=true
fi

which >/dev/null 2>/dev/null $askcmdstr

if [ $? -ne 0 ] ; then
	canask=false
else
	canask=true
fi

###

if ( ! $canask ) && ( ! $isroot ) ; then
   echo "This script needs root privileges, exiting..." 1>&2
   exit 1
fi

#===========================================


if $isroot ; then

	for cmdindex in ${!commands[*]} ; do
		echo "running: \"${commands[cmdindex]}\"..."
		${commands[cmdindex]}
	done

	exit $?
fi


if $canask ; then

	for cmdindex in ${!commands[*]} ; do
		#echo "running: \"${commands[cmdindex]}\"..."
		$asksucmd "${commands[cmdindex]}"
	done

	exit $?
fi

